﻿using System;
using System.Threading;
using CatClient.Message;
using CatClient.Util;
using CatClient;
using PostSharp.Aspects;
using PostSharp.Aspects.Internals;
using PostSharp.Extensibility;

namespace PsCat.Aspet
{
    // Token: 0x02000005 RID: 5
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
    [HasInheritedAttribute(new long[]
    {

    })]
    [Serializable]
    public class CatAttribute : CatBaseAttribute
    {
        // Token: 0x0600000D RID: 13 RVA: 0x0000226E File Offset: 0x0000046E
        public CatAttribute(string type = "", string name = "")
        {
            this._type = type;
            this._name = name;
        }

        // Token: 0x0600000E RID: 14 RVA: 0x00002284 File Offset: 0x00000484
        [HasInheritedAttribute(new long[]
        {
            -966559710620335241L
        })]
        [MethodExecutionAdviceOptimization(MethodExecutionAdviceOptimizations.IgnoreSetFlowBehavior | MethodExecutionAdviceOptimizations.IgnoreGetArguments | MethodExecutionAdviceOptimizations.IgnoreSetArguments | MethodExecutionAdviceOptimizations.IgnoreGetInstance | MethodExecutionAdviceOptimizations.IgnoreSetInstance | MethodExecutionAdviceOptimizations.IgnoreGetException | MethodExecutionAdviceOptimizations.IgnoreGetReturnValue | MethodExecutionAdviceOptimizations.IgnoreSetReturnValue | MethodExecutionAdviceOptimizations.IgnoreGetMethodExecutionTag | MethodExecutionAdviceOptimizations.IgnoreGetYieldValue | MethodExecutionAdviceOptimizations.IgnoreSetYieldValue | MethodExecutionAdviceOptimizations.IgnoreGetDeclarationIdentifier)]
        public override void OnEntry(MethodExecutionArgs args)
        {
            try
            {
                if (Cat.IsInitialized())
                {
                    if (string.IsNullOrWhiteSpace(this._name))
                    {
                        this._name = this.NameFormClassMethod(args);
                    }
                    args.MethodExecutionTag = Cat.NewTransaction(this._type, this._name);
                    Cat.LogEvent(this._type, this._name, "0", null);
                }
            }
            catch (Exception ex)
            {
                LogInfoWriter.GetInstance("Cat", 0, LogInfoWriter.LogLayout.Default).Error(ex.Message, ex);
            }
        }

        // Token: 0x0600000F RID: 15 RVA: 0x00002310 File Offset: 0x00000510
        [HasInheritedAttribute(new long[]
        {
            -966559711310300280L
        })]
        [MethodExecutionAdviceOptimization(MethodExecutionAdviceOptimizations.IgnoreGetMethod | MethodExecutionAdviceOptimizations.IgnoreSetFlowBehavior | MethodExecutionAdviceOptimizations.IgnoreGetArguments | MethodExecutionAdviceOptimizations.IgnoreSetArguments | MethodExecutionAdviceOptimizations.IgnoreGetInstance | MethodExecutionAdviceOptimizations.IgnoreSetInstance | MethodExecutionAdviceOptimizations.IgnoreGetException | MethodExecutionAdviceOptimizations.IgnoreGetReturnValue | MethodExecutionAdviceOptimizations.IgnoreSetReturnValue | MethodExecutionAdviceOptimizations.IgnoreSetMethodExecutionTag | MethodExecutionAdviceOptimizations.IgnoreGetYieldValue | MethodExecutionAdviceOptimizations.IgnoreSetYieldValue | MethodExecutionAdviceOptimizations.IgnoreGetDeclarationIdentifier)]
        public override void OnExit(MethodExecutionArgs args)
        {
            try
            {
                ITransaction transaction = (ITransaction)args.MethodExecutionTag;
                if (transaction != null)
                {
                    transaction.Complete();
                }
            }
            catch (Exception ex)
            {
                LogInfoWriter.GetInstance("Cat", 0, LogInfoWriter.LogLayout.Default).Error(ex.Message, ex);
            }
        }

        // Token: 0x06000010 RID: 16 RVA: 0x00002360 File Offset: 0x00000560
        [HasInheritedAttribute(new long[]
        {
            -966559710091859626L
        })]
        [MethodExecutionAdviceOptimization(MethodExecutionAdviceOptimizations.IgnoreGetMethod | MethodExecutionAdviceOptimizations.IgnoreSetFlowBehavior | MethodExecutionAdviceOptimizations.IgnoreGetArguments | MethodExecutionAdviceOptimizations.IgnoreSetArguments | MethodExecutionAdviceOptimizations.IgnoreGetInstance | MethodExecutionAdviceOptimizations.IgnoreSetInstance | MethodExecutionAdviceOptimizations.IgnoreGetException | MethodExecutionAdviceOptimizations.IgnoreGetReturnValue | MethodExecutionAdviceOptimizations.IgnoreSetReturnValue | MethodExecutionAdviceOptimizations.IgnoreSetMethodExecutionTag | MethodExecutionAdviceOptimizations.IgnoreGetYieldValue | MethodExecutionAdviceOptimizations.IgnoreSetYieldValue | MethodExecutionAdviceOptimizations.IgnoreGetDeclarationIdentifier)]
        public override void OnSuccess(MethodExecutionArgs args)
        {
            ITransaction transaction = (ITransaction)args.MethodExecutionTag;
            if (transaction != null)
            {
                transaction.Status = "0";
            }
        }

        // Token: 0x06000011 RID: 17 RVA: 0x00002388 File Offset: 0x00000588
        [HasInheritedAttribute(new long[]
        {
            -966559711086782217L
        })]
        [MethodExecutionAdviceOptimization(MethodExecutionAdviceOptimizations.IgnoreGetMethod | MethodExecutionAdviceOptimizations.IgnoreSetFlowBehavior | MethodExecutionAdviceOptimizations.IgnoreGetArguments | MethodExecutionAdviceOptimizations.IgnoreSetArguments | MethodExecutionAdviceOptimizations.IgnoreGetInstance | MethodExecutionAdviceOptimizations.IgnoreSetInstance | MethodExecutionAdviceOptimizations.IgnoreGetReturnValue | MethodExecutionAdviceOptimizations.IgnoreSetReturnValue | MethodExecutionAdviceOptimizations.IgnoreSetMethodExecutionTag | MethodExecutionAdviceOptimizations.IgnoreGetYieldValue | MethodExecutionAdviceOptimizations.IgnoreSetYieldValue | MethodExecutionAdviceOptimizations.IgnoreGetDeclarationIdentifier)]
        public override void OnException(MethodExecutionArgs args)
        {
            ITransaction transaction = (ITransaction)args.MethodExecutionTag;
            if (transaction != null)
            {
                Exception exception = args.Exception;
                if (((exception != null) ? exception.GetType() : null) == CatAttribute.ThreadAbortExceptionType)
                {
                    transaction.Status = "0";
                    return;
                }
                transaction.SetStatus(args.Exception);
            }
        }

        // Token: 0x04000003 RID: 3
        private readonly string _type;

        // Token: 0x04000004 RID: 4
        private string _name;

        // Token: 0x04000005 RID: 5
        private static readonly Type ThreadAbortExceptionType = typeof(ThreadAbortException);
    }
}
